<template>
  <div>
    <div class="control">
      <div class="inputItem">
        <div class="title">供应商名称</div>
        <div class="inputBox">
          <el-input v-model="supplierName" @keyup.enter.native="cread">
          </el-input>
        </div>
      </div>
      <div class="inputItem">
        <div class="title">车队名称</div>
        <div class="inputBox">
          <el-input v-model="fleetName" @keyup.enter.native="cread">
          </el-input>
        </div>
      </div>
      <!-- 查询 -->
      <el-button
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="cread"
        >筛选</el-button
      >
      <el-button
        type="plain"
        size="small"
        icon="el-icon-refresh-right"
        @click="CleanUp"
        >清空</el-button
      >
    </div>
    <div class="main">
      <div class="list">
        <el-table :data="records" style="width: 100%" ref="table5">
          <el-table-column align="center" prop="serialNumber" label="序号">
            <template slot-scope="scope">
              {{ scope.$index * ((pageCurrent - 1) * 10 + 1) + 1 }}
            </template>
            <!-- 不要再写scope.$index + 1这种方法第二页又从1开始数,后面统一下 你请求列表调我那个前端序号方法 -->
          </el-table-column>
          <el-table-column align="center" prop="bsupplierName" label="申请绑定供应商">
          </el-table-column>
          <el-table-column align="center" prop="fleetName" label="车队名称">
          </el-table-column>
          <el-table-column align="center" prop="address" label="车队地址">
          </el-table-column>
          <el-table-column align="center" prop=" type" label="类型">
            <template slot-scope="scope">
              <div v-if="scope.row.type===0" style="color: cornflowerblue;">
                新增
              </div>
              <div v-else style="color: #da2a2a;">
                解绑
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="status" label="状态">
            <template slot-scope="scope">
              <div v-if="scope.row.status==1"  style="color: cornflowerblue;">
                通过
              </div>
              <div v-else-if="scope.row.status==2" style="color: #da2a2a;" >
                驳回
              </div>
              <div v-else>
                待审核
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <div>
                <el-button type="text" size="small" v-if="scope.row.status===0" @click="sumbit(scope.row,1)">同意</el-button>
                <el-button type="text" size="small"  v-if="scope.row.status===0" @click="sumbit(scope.row,2)">不同意</el-button>
                <el-button type="text" size="small"  v-if="scope.row.status==2 & scope.row.type===0" @click="jieban(scope.row)">解绑</el-button>

                <el-button type="text" size="small" 
                @click="
                  $router.push({
                    path: '/home/fleetManagement/details',
                    query: { fleetId: scope.row.fleetId, type: 'external' },
                  })"
                >详情</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <div class="paginationBox">
        <el-pagination
          class="pagination"
          background
          layout="slot,prev, pager, next"
          :total="data.total * 1"
          :page-size="data.size * 1"
          :pager-count="5"
          @current-change="changePages($event)"
        >
          <template slot>
            <span
              style="
                color: #686868;
                font-size: 12px;
                margin-right: 20px;
                display: inline-block;
              "
              >共{{ data.total }}条,每页{{ pageSize }}条</span
            >
          </template>
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      driverName: "",
      data: {
        total: "",
        size: "",
        pages: "",
      },
      status:'',
      type:'',
      supplierName:'',
      fleetName:'',
      records: [],
      pageCurrent: 1, //当前页码
      pageSize: "10", //每页10条
    };
  },
  created() {
    this.cread();
  },
  methods: {
    changePages(e) {
      this.pageCurrent = e;
      this.cread();
    },
    async jieban(e){
      let that = this;
      this.$confirm("此操作将解绑被绑定的外部车队", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          that.request(e);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    async request(e) {
      let res = await this.$http.fleetManagementApi.delExternalFleet({
        fleetId: e.fleetId,
        supplierId:e.supplierId
      });
      if (res.data.code == "200") {
        this.$message.success("解绑成功");
        this.cread();
      }
    },
  async  sumbit(e,i){
    let res = await this.$http.fleetManagementApi.ExternalExamineFleet({fid:e.fid,status:i})
    if(res.data.code=='200'){
      this.$message.success('审核成功')
      this.cread();
    }
    },
    async cread() {
      let res = await this.$http.fleetManagementApi.queryExternalExamineFleet({
        status: this.status, //  -1全部0待审核1同意2拒绝
        supplierName: this.supplierName,
        fleetName: this.fleetName, // 司机名称
        current: this.pageCurrent,
        size: this.pageSize,
      });
      this.records = res.data.data.records;
      this.data = res.data.data;
    },

    CleanUp() {
      this.supplierName = ''
      this.fleetName = ''
      this.cread();
    },

    // 记录滚动距离
    scrollEvent(res) {
      this.$route.meta.scrollTop = res.target.scrollTop;
      //console.log(res.target.scrollTop);
    },
  },
  activated() {
    //组件激活时监听表格滚动条位置,
    this.$refs.table5.bodyWrapper.addEventListener(
      "scroll",
      this.scrollEvent,
      false
    );
    // 激活设置滚动位置
    this.$refs.table5.bodyWrapper.scrollTop = this.$route.meta.scrollTop;
  },
  beforeRouteLeave(to, from, next) {
    // 为了节省资源，再离开页面的时候关闭对于scroll事件的监听
    this.$refs.table5.bodyWrapper.removeEventListener(
      "scroll",
      this.scrollEvent
    );
    next();
  },

  mounted() {
    this.cread();
  },
};
</script>

<style lang="scss" scoped>
.control {
  height: 76px;
  width: 100%;
  background-color: #fff;
  display: flex;
  align-items: center;
  padding: 0 29px;

  .inputItem {
    display: flex;
    align-items: center;
    margin-right: 23px;

    > .title {
      color: #262626;
      font-size: 12px;
      margin-right: 7px;
    }

    > .inputBox {
      width: 160px;

      ::v-deep .el-input__inner {
        height: 32px;
        font-size: 12px;
      }

      ::v-deep .el-input__inner::placeholder {
        color: #c3c3c3;
        font-size: 12px;
      }
    }

    ::v-deep .el-input__icon {
      line-height: 0;
    }
  }
}

.main {
  width: 100%;
  height: calc(100vh - 266px);

  background-color: #fff;

  .list {
    height: calc(100% - 48px);
    padding: 0 30px;

    ::v-deep .el-table__body-wrapper {
      height: calc(100vh - 361px) !important;
      overflow-y: scroll;
    }

    // 表头样式
    ::v-deep .el-table__header th {
      background-color: #f0f6fd;
      color: #262626;
      font-size: 12px;
      font-weight: bold;
      text-align: center;
      height: 48px;
      padding: 0;

      // 表 body的td
      ::v-deep .el-table__body td {
        color: #595959;
        font-size: 12px;
      }
    }

    .tag {
      width: 63px;
      height: 28px;
      font-size: 12px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 4px;
      margin: 0 auto;

      .dian {
        width: 4px;
        height: 4px;
        border-radius: 50%;
        margin-right: 4px;
      }

      &.yellow {
        background-color: #fffce8;
        color: #f9aa0d;

        .dian {
          background-color: #f9aa0d;
        }
      }

      &.dispatched {
        background-color: #ecf5fe;
        color: #1890ff;

        .dian {
          background-color: #1890ff;
        }
      }

      &.red {
        background-color: #fde8e9;
        color: #f7555d;

        .dian {
          background-color: #f7555d;
        }
      }
    }

    .stateBtns {
      height: 30px;
      width: 76px;

      ::v-deep .el-button {
        height: 30px;
        width: 76px;
        font-size: 12px;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 30px;
      }

      .waitPass {
        background-color: #ecf5fe;
        color: #1890ff;
      }

      .noPass {
        background-color: #fde8e9;
        color: #f7555d;
      }
    }
  }

  .paginationBox {
    border-top: 1px solid #f0f0f0;
    width: 100%;
    background-color: #fff;
    display: flex;
    height: 48px;
    align-items: center;
    padding: 0 30px;

    .pagination {
      margin-left: auto;
    }
  }
}

.dialog {
  ::v-deep .el-dialog__header {
    border-bottom: 1px solid #f0f0f0;
    padding: 15px 20px;
    color: #262626;
    font-size: 14px;
    font-weight: bold;
    height: 50px;
  }

  ::v-deep .el-dialog__title {
    font-size: 14px;
    color: #303133;
    font-weight: bold;
  }

  //关闭图标
  ::v-deep .el-dialog__headerbtn .el-dialog__close {
    font-size: 15px;
  }

  ::v-deep .el-dialog__body {
    padding: 20px;
  }

  ::v-deep .el-form-item__label {
    line-height: 32px;
    font-size: 12px;
    color: #262626;
    padding-top: 4px;
  }

  .upload {
    .uploadBtn {
      width: 80px;
      height: 32px;
      background-color: #1890ff;
      font-size: 12px;
      color: #fff;
      cursor: pointer;
      border-radius: 4px;
      transition: 0.2s;
      margin-right: 12px;
      margin-bottom: 8px;

      &:hover {
        opacity: 0.8;
      }
    }

    .el-upload__tip {
      color: #cccccc;
      font-size: 12px;
    }

    ::v-deep .el-upload-list {
      background-color: #eef3f9;
    }
  }

  .cancelBtn {
    width: 80px;
    height: 36px;
    border: 1px solid #d9d9d9;
    color: #262626;
    font-size: 12px;
    border-radius: 4px;
    background-color: #fff;
    transition: 0.2s;

    &:hover {
      color: #1890ff;
      border-color: #c6e2ff;
      background-color: #ecf5ff;
    }
  }

  .submitBtn {
    background-color: #1890ff;
    width: 80px;
    height: 36px;
    color: #fff;
    border-radius: 4px;
    font-size: 12px;
    transition: 0.2s;

    &:hover {
      opacity: 0.8;
    }
  }
}

.nullPng {
  height: 300px;
  width: 100%;
  font-weight: 600;
  display: flex;
  justify-content: center;

  & div {
    text-align: center;
  }
}
</style>
